package com.neusoft.controller;

import com.neusoft.dto.EmpLoginADto;
import com.neusoft.dto.EmpLoginEDto;
import com.neusoft.service.LoginService;
import com.neusoft.vo.EmpLoginVo;
import com.neusoft.vo.EmpVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 王柯淋
 * @Date 2025/1/8 20:58
 * @DESCRIBER
 */
@RestController
@RequestMapping("/api")
public class LoginController {
    @Autowired
    LoginService loginService;
    @PostMapping("/loginE")
    public EmpLoginVo EmailLogin(@RequestBody EmpLoginEDto empLoginEDto){
        return loginService.EmailLogin(empLoginEDto);
    }
    @PostMapping("/loginA")
    public EmpLoginVo AccountLogin(@RequestBody EmpLoginADto empLoginADto){
        System.out.println(loginService.AccountLogin(empLoginADto));
        return loginService.AccountLogin(empLoginADto);
    }
    @PostMapping("/resetPwd")
    public String ReSetPassword(@RequestBody EmpLoginEDto empLoginEDto){
        //重置密码
        String rePassword = loginService.ReSetPassword(empLoginEDto);
        //通过邮箱发送重置后的密码
        loginService.SendEmail(empLoginEDto.getEmpEmail(), rePassword);
        System.out.println("重置密码成功，已发送至邮箱"+empLoginEDto.getEmpEmail());
        return rePassword;
    }
    @PostMapping("/updatePwd")
    public String UpdatePassword(@RequestBody String newPassword){
        return loginService.UpdatePassword(newPassword);
    }
}
